<html>
<head><meta charset="utf-8"><title>Populating cache before intra-doc links · rustdoc · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/index.html">rustdoc</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links.html">Populating cache before intra-doc links</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226174690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Populating%20cache%20before%20intra-doc%20links/near/226174690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links.html#226174690">(Feb 12 2021 at 18:06)</a>:</h4>
<p>I want to populate the cache before running intra-doc links (for <a href="https://github.com/rust-lang/rust/pull/82014">https://github.com/rust-lang/rust/pull/82014</a>). Right now that breaks links to traits:</p>
<div class="codehilite" data-code-language="Diff"><pre><span></span><code>&gt; diff /home/joshua/rustc2/build/x86_64-unknown-linux-gnu/test/rustdoc/intra-doc/trait-impl.nightly/foo/trait.MyTrait.html /home/joshua/rustc2/build/x86_64-unknown-linux-gnu/test/rustdoc/intra-doc/trait-impl/foo/trait.MyTrait.html
128c128
&lt;               &lt;a href="../foo/struct.MyStruct.html#associatedtype.AssoType"&gt;&lt;code&gt;AssoType&lt;/code&gt;&lt;/a&gt;
<span class="gd">---</span>
&gt;               &lt;a href="MyStruct::AssoType"&gt;&lt;code&gt;AssoType&lt;/code&gt;&lt;/a&gt;
136c136
&lt;               &lt;a href="../foo/struct.MyStruct.html#associatedconstant.ASSO_CONST"&gt;&lt;code&gt;ASSO_CONST&lt;/code&gt;&lt;/a&gt;
<span class="gd">---</span>
&gt;               &lt;a href="MyStruct::ASSO_CONST"&gt;&lt;code&gt;ASSO_CONST&lt;/code&gt;&lt;/a&gt;
144c144
&lt;               &lt;a href="../foo/struct.MyStruct.html#method.trait_fn"&gt;&lt;code&gt;trait_fn&lt;/code&gt;&lt;/a&gt;
<span class="gd">---</span>
&gt;               &lt;a href="MyStruct::trait_fn"&gt;&lt;code&gt;trait_fn&lt;/code&gt;&lt;/a&gt;
</code></pre></div>
<p>I think this is happening because intra-doc links themselves fill out parts of the cache: <a href="https://github.com/rust-lang/rust/blob/a118ee2c13cc96ceb27bd5030c1cca1052377604/src/librustdoc/passes/collect_intra_doc_links.rs#L1245">https://github.com/rust-lang/rust/blob/a118ee2c13cc96ceb27bd5030c1cca1052377604/src/librustdoc/passes/collect_intra_doc_links.rs#L1245</a>.</p>
<p>There are two issues here:</p>
<ul>
<li><a href="https://github.com/rust-lang/rust/blob/d416093209d0dd77a4cdeb5a2f1b5de1316787ec/src/librustdoc/clean/inline.rs#L626"><code>register_external_trait</code></a> writes to <code>cx.external_traits</code>, which is what is used to populate the cache. So if I populate the cache before running intra-doc links, the new traits will never be moved into the cache and just sit there uselessly. I tried to fix this by draining <code>cx.external_traits</code> after runing all passes, but it didn't work, I think because the logic in <code>populate</code> isn't running: <a href="https://github.com/rust-lang/rust/blob/334b40effde4983ff0cda18306ec46419806f717/src/librustdoc/formats/cache.rs#L196">https://github.com/rust-lang/rust/blob/334b40effde4983ff0cda18306ec46419806f717/src/librustdoc/formats/cache.rs#L196</a>. I might be able to fix it by calling populate twice, but that doesn't fix the second issue which is </li>
<li><a href="https://github.com/rust-lang/rust/blob/d416093209d0dd77a4cdeb5a2f1b5de1316787ec/src/librustdoc/html/format.rs#L485"><code>href</code></a> looks only at the cache, so anything which modifies <code>cx.external_traits</code> (intra-doc links) will see incomplete info, because the stuff it just added hasn't been propagated through the cache yet. That means even if I manage to get this to work in the sense of having the previous behavior, it still won't be accurate.</li>
</ul>
<p>I guess my questions are</p>
<ul>
<li>Is there a way to tell whether an item will have documentation generated before having to calculate the full URL?</li>
<li>If not, is it possible to change <code>register_res</code> to work eagerly, so there's no 'flushing' of the cache necessary?</li>
</ul>
<p>Maybe it would be easier to move this check out of intra-doc links altogether ...</p>



<a name="226174967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Populating%20cache%20before%20intra-doc%20links/near/226174967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links.html#226174967">(Feb 12 2021 at 18:09)</a>:</h4>
<p><span class="user-mention" data-user-id="210316">@GuillaumeGomez</span> would be interested in your thoughts :)</p>



<a name="226177244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Populating%20cache%20before%20intra-doc%20links/near/226177244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> GuillaumeGomez <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links.html#226177244">(Feb 12 2021 at 18:28)</a>:</h4>
<p>Anything cache-related isn't behaving the same depending at which phase we are and it's a bit problematic. If you know what the issue is, you can always try to work around and identify clearly what shouldn't have access to the cache. At least it's how I do it generally. It got simpler lately so if we continue like that, we might even be able to use the cache everywhere without worrying.</p>



<a name="226178254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Populating%20cache%20before%20intra-doc%20links/near/226178254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links.html#226178254">(Feb 12 2021 at 18:37)</a>:</h4>
<p>well I don't know if intra-doc links <em>shouldn't</em> have access to the cache is the issue</p>



<a name="226178940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Populating%20cache%20before%20intra-doc%20links/near/226178940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> GuillaumeGomez <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links.html#226178940">(Feb 12 2021 at 18:43)</a>:</h4>
<p>I don't see why it shouldn't. But does the cache provides information you can't get otherwise?</p>



<a name="226179011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Populating%20cache%20before%20intra-doc%20links/near/226179011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links.html#226179011">(Feb 12 2021 at 18:43)</a>:</h4>
<p>yes, specifically I want to know if an item will have documentation generated</p>



<a name="226179071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Populating%20cache%20before%20intra-doc%20links/near/226179071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links.html#226179071">(Feb 12 2021 at 18:44)</a>:</h4>
<p>which I do currently by calling <code>href(def_id).is_some()</code>, which breaks because the cache is still being constructed</p>



<a name="226179339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Populating%20cache%20before%20intra-doc%20links/near/226179339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links.html#226179339">(Feb 12 2021 at 18:47)</a>:</h4>
<p>if there's an easier way to do that I'm all ears :)</p>



<a name="226195646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Populating%20cache%20before%20intra-doc%20links/near/226195646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> GuillaumeGomez <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links.html#226195646">(Feb 12 2021 at 21:02)</a>:</h4>
<p>I'd say: construct the cache first? XD</p>



<a name="226208327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/Populating%20cache%20before%20intra-doc%20links/near/226208327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links.html#226208327">(Feb 12 2021 at 23:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="210316">GuillaumeGomez</span> <a href="#narrow/stream/266220-rustdoc/topic/Populating.20cache.20before.20intra-doc.20links/near/226195646">said</a>:</p>
<blockquote>
<p>I'd say: construct the cache first? XD</p>
</blockquote>
<p>this isn't possible AFAICT because there are some items that are only used if intra-doc links link to them</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>